package com.letv.core.parser;

import org.json.JSONObject;

import android.text.TextUtils;

import com.letv.core.bean.TicketUseBean;

/**
 * 观影券使用结果
 * 
 * @author zhuqiao
 *
 */
public class TicketUseParser extends LetvBaseParser<TicketUseBean, String> {

    public TicketUseParser() {
        super(0);
    }

    @Override
    protected TicketUseBean parse(String data) throws Exception {
        TicketUseBean bean = new TicketUseBean();

        try {
            JSONObject jsonObject = new JSONObject(data);
            int code = getInt(jsonObject, "code");
            String values = jsonObject.getString("values");
            String msg = getString(new JSONObject(values), "msg");
            bean.setCode(code);
            bean.setMsg(msg);
        } catch (Exception e) {
            JSONObject jsonObject = new JSONObject(data);
            int code = getInt(jsonObject, "code");
            String values = getString(jsonObject, "values");
            bean.setCode(code);
            bean.setMsg(values);
        }

        return bean;
    }

    @Override
    protected boolean canParse(String data) {
        return !TextUtils.isEmpty(data);
    }

    @Override
    protected String getData(String data) throws Exception {
        return data;
    }

}
